import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', {
  state: () => ({ count: 0, isShow: false }),
  actions: {
    // 同步方法
    increment() {
      this.count++
    },
    // 展示或者关闭方法
    showOrHide() {
      this.isShow = !this.isShow
    },
    // 异步调用
    async fetchUsers() {
      this.loading = true
      try {
        const response = await fetch('/api/users')
        this.users = await response.json()
      } finally {
        this.loading = false
      }
    },
  },
})
